#include <functional>
#include <memory>
#include <iostream>
using namespace std;

int main() {
    shared_ptr<int> sp = shared_ptr<int>(new int(42));
    weak_ptr<int> wp = sp;

    std::cout << "Initial use_count: " << sp.use_count() << std::endl; // 输出: 1

    {
        shared_ptr<int> sp_locked = wp.lock();
        if (sp_locked.get()) {
            std::cout << "Locked value: " << *sp_locked.get() << std::endl; // 输出: 42
            std::cout << "Locked use_count: " << sp_locked.use_count() << std::endl; // 输出: 2
        } else {
            std::cout << "wp is expired" << std::endl;
        }
    }

    std::cout << "Final use_count: " << sp.use_count() << std::endl; // 输出: 1

    return 0;
}